<template>
  <div class="container">
    <Modal v-model="addSubject" title="新增文章" @on-ok="addOk" @on-cancel="addCancel" :footer-hide="true" :closable="false" :mask-closable="false" width='800' height='500'>
      <Form :model="formItem" :label-width="100" :rules="ruleValidate" ref="ruleForm">
        <FormItem label="文章标签" prop='title'>
          <Input v-model="formItem.title" placeholder="请输入文章标签"></Input>
        </FormItem>
        <FormItem label="文章内容" prop="articleBody" style="height:150px;margin-bottom:75px">
          <quill-editor v-model="formItem.articleBody" :options="editorOption" style="height: 150px" />
        </FormItem>
        <FormItem label="视频地址">
          <Input placeholder="请输入视频地址"></Input>
        </FormItem>
      </Form>
      <Row type="flex" justify="end">
        <Button @click="addCancel">取消</Button>
        <Button type="primary" @click="addOk" style="margin-left: 15px">确定</Button>
      </Row>
    </Modal>
  </div>
</template>

<script>
import { add } from '@/api/hmmm/articles'

export default {
  props: {
    addSubject: {
      type: Boolean,
      default: false
    }
  },
  data () {
    return {
      formItem: {
        title: '',
        articleBody: '',
        videoURL: ''
      },
      ruleValidate: {
        title: [
          { required: true, message: '名称不能为空', trigger: 'blur' }
        ],
        articleBody: [
          { required: true, message: '学科不能为空', trigger: 'blur' }
        ]
      },
      editorOption: {
        //  富文本编辑器配置
        modules: {
          // 工具栏定义的
          toolbar: [
            ['bold', 'italic', 'underline', 'strike'], // 加粗 斜体 下划线 删除线 -----['bold', 'italic', 'underline', 'strike']
            [{ list: 'ordered' }, { list: 'bullet' }], // 有序、无序列表-----[{ list: 'ordered' }, { list: 'bullet' }]
            ['blockquote', 'code-block'], // 引用  代码块-----['blockquote', 'code-block']
            ['image', 'link'] // 链接、图片、视频-----['link', 'image', 'video']
          ]
        },
        // 主题
        placeholder: ''
      },
      science: [],
      itemList: {}
    }
  },
  methods: {
    // 点击确定
    async addOk () {
      try {
        this.$refs.ruleForm.validate()
        console.log(this.formItem.title)
        console.log(this.formItem.articleBody)
        this.itemList.title = this.formItem.title
        this.itemList.articleBody = this.formItem.articleBody
        console.log(this.itemList)
        await add(this.itemList)
        this.$Message.success('添加成功')
        this.$parent.getRoleList()
        this.$refs.ruleForm.resetFields()
        this.$emit('update:addSubject', false)
      } catch (error) {
        console.log(error)
      }
    },
    // 点击取消
    addCancel () {
      this.$refs.ruleForm.resetFields()
      this.$emit('update:addSubject', false)
    }
  }
}
</script>

<style scoped>
 /deep/.ivu-modal-header {
  background-color: #409EFF !important;
}
/deep/.ivu-modal-header-inner {
  color: white !important;
}
/deep/.ivu-modal-content {
  height: 500px !important;
}
/deep/.ivu-row-end {
  margin-top: 40px;
}
</style>
